package com.front.frontdemo.controller;

import com.example.comm.client.MDiaryClient;
import com.example.comm.vo.MDiary;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 时间流逝action
 */
@RequestMapping("/MDiary")
@RestController
public class MDiaryController {

    @Resource
    private MDiaryClient mDiaryClient;

    @GetMapping("/searchByPage")
    public @ResponseBody
    Map searchByPage(Integer limit, Integer offset,String name){
        Map gson = new HashMap();
        if (name != null && !(name.trim().equals(""))){
            gson.put("name_cons", name.trim());
        }
        gson.put("rows", limit);
        gson.put("page", offset / limit);
        gson.put("orderby_id","desc");
        return mDiaryClient.searchByPage(gson);
    }

    @PostMapping("/add")
    public Map add(MDiary mDiary) {
        return mDiaryClient.add(mDiary);
    }

}
